package com.example.dell.fastshopping.product;

import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;

import com.example.dell.fastshopping.network.ApiService;
import com.example.dell.fastshopping.network.NetCallback;
import com.example.dell.fastshopping.network.RetrofitClient;
import com.example.dell.fastshopping.network.http.BaseResponse;
import com.example.dell.fastshopping.utils.KLog;
import com.youth.banner.Banner;

import java.util.List;

/**
 * Created by ${YSH} on 2019/5/28.
 * 描述        ${TODO}
 * <p>
 * 更新者       $author$
 * 更新时间     $Data$
 * 描述         ${TODO}
 */
public class ProductModel extends ViewModel {
    private MutableLiveData<List<ProductMenu>> leftMune = new MutableLiveData();
    private MutableLiveData<ProductMenu> selectValue = new MutableLiveData();
    private MutableLiveData<List<Product>> products = new MutableLiveData();
    private MutableLiveData<List<BannerEntity>> banner = new MutableLiveData();
    private ApiService service = RetrofitClient.getInstance().create(ApiService.class);

    public MutableLiveData<List<ProductMenu>> getProductType() {
        RetrofitClient.execute(service.getProductMenu(), new NetCallback<BaseResponse<List<ProductMenu>>>() {
            @Override
            public void netCallback(BaseResponse<List<ProductMenu>> o) {
                leftMune.setValue(o.getData());
            }
        });
        return leftMune;
    }

    public void setSelectValue(ProductMenu value) {
        this.selectValue.setValue(value);
    }

    public MutableLiveData<ProductMenu> getSelect() {
        return selectValue;
    }

    public MutableLiveData<List<Product>> getProduct(String id) {
        RetrofitClient.execute(service.getProduct(id), new NetCallback<BaseResponse<List<Product>>>() {
            @Override
            public void netCallback(BaseResponse<List<Product>> o) {
                products.setValue(o.getData());
            }
        });
        return products;
    }

    public MutableLiveData<List<BannerEntity>> getProductBanner() {
        RetrofitClient.execute(service.getProductBanner(1), new NetCallback<BaseResponse<List<BannerEntity>>>() {
            @Override
            public void netCallback(BaseResponse<List<BannerEntity>> o) {
                banner.setValue(o.getData());
            }
        });
        return banner;
    }
}
